<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('goods-brand');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回品牌列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存品牌'); ?></button>
            <?php echo $this->HelpUrl('goodsBrandAdd'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab"><?php echo $this->translate('基本信息'); ?></a></li>
                        <li><a href="#tab_4" data-toggle="tab"><?php echo $this->translate('所在商品分类'); ?></a></li>
                        <?php if(isset($this->brandInfo)) { ?>
                            <li><a href="#tab_2" data-toggle="tab"><?php echo $this->translate('品牌商品'); ?></a></li>
                        <?php } ?>
                        <li><a href="#tab_3" data-toggle="tab"><?php echo $this->translate('SEO优化'); ?></a></li>
                    </ul>
                    <div class="tab-content">
                        <?php echo $this->partial('layout/messages'); ?>
                        <div class="tab-pane active" id="tab_1">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('品牌名称'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('brandName')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandName'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('品牌logo'); ?></label>
                                    <div class="col-sm-4">
                                        <?php if(is_string($form->get('brandLogo')->getValue())) { ?>
                                            <img src="<?php echo $this->basePath($form->get('brandLogo')->getValue()); ?>" style="max-width: 300px;padding-bottom: 5px;">
                                        <?php } ?>
                                        <?php echo $this->formElement($form->get('brandLogo')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandLogo'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('品牌排序'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('brandSort')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandSort'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('品牌描述'); ?></label>
                                    <div class="col-sm-10">
                                        <script id="brandInfo" name="brandInfo" type="text/plain"><?php echo isset($this->brandInfo) ? $this->brandInfo->getBrandInfo() : $form->get('brandInfo')->getValue(); ?></script>
                                        <?php echo $this->formElementErrors($form->get('brandInfo'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php if(isset($this->brandInfo)) { ?>
                            <div class="tab-pane" id="tab_2">
                                <div class="box-body table-responsive no-padding" id="goodsListBody">
                                    <table class="table shop-table">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th width="5%">ID</th>
                                            <th width="45%"><?php echo $this->translate('商品名称'); ?></th>
                                            <th width="15%"><?php echo $this->translate('商品状态'); ?></th>
                                            <th width="10%"><?php echo $this->translate('操作'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php if(isset($this->goodsList)) foreach ($this->goodsList as $goodsValue) { ?>
                                            <tr id="in-goods-<?php echo $goodsValue->getGoodsId(); ?>">
                                                <td><?php echo $goodsValue->getGoodsId(); ?></td>
                                                <td><?php echo $this->escapeHtml($goodsValue->getGoodsName()); ?></td>
                                                <td><?php echo $this->goodsHelper()->goodsState($goodsValue->getGoodsState()); ?></td>
                                                <td>
                                                    <a href="javascript:;" onclick="deleteNotConfirm( '<?php echo $this->url('goods-brand', ['action'=>'deleteBrandGoods', 'id'=>$goodsValue->getGoodsId()]); ?>', 'in-goods-<?php echo $goodsValue->getGoodsId(); ?>');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></a>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <td colspan="4">
                                                <?php echo $this->paginationControl($this->goodsList,
                                                    'Sliding',
                                                    'layout/ajaxPage',
                                                    ['route' => 'goods-brand', 'params' => ['action' => 'ajaxBrandGoods', 'id' => $this->brandInfo->getBrandId()], 'showDivId' => 'goodsListBody']); ?>
                                            </td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        <?php } ?>
                        <div class="tab-pane" id="tab_3">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('扩展名称'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('brandNameExtend')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandNameExtend'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('品牌关键字'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('brandKeywords')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandKeywords'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('品牌描述'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('brandDescription')); ?>
                                        <?php echo $this->formElementErrors($form->get('brandDescription'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_4">
                            <div class="box-body">
                                <?php echo $this->formElementErrors($form->get('inClassId'), ['class'=>'error-message']); ?>
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-hover">
                                        <tbody>
                                        <?php if($this->classList) foreach ($this->classList as $classValue) { ?>
                                            <tr>
                                                <td>
                                                    <label class="checkbox-inline">
                                                        <?php if($classValue->getClassTopId() > 0) echo str_repeat('&nbsp;', substr_count($classValue->getClassPath(), ',') * 3); ?>
                                                        <input onclick="selectClassId('<?php echo $classValue->getClassPath(); ?>', <?php echo $classValue->getClassId(); ?>);" name="inClassId[]" <?php if(isset($this->selectedClass) && !empty($this->selectedClass) && in_array($classValue->getClassId(), $this->selectedClass)) echo 'checked'; ?> id="classId<?php echo $classValue->getClassId(); ?>" value="<?php echo $classValue->getClassId(); ?>" type="checkbox" class="minimal">
                                                        <?php echo $this->escapeHtml($classValue->getClassName() . ' (ID：' . $classValue->getClassId() . ')'); ?>
                                                    </label>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<?php echo $this->partial('common/editor',['edit_array'=>['brandInfo'],'edit_config'=>["toolbars:[['FullScreen', 'Source', 'Undo', 'Redo','Bold']]", "initialFrameHeight:150"]]); ?>
<script>
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                brandName: {
                    required: true
                },
                brandSort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                brandName: {
                    required: "<?php echo $this->translate('品牌名称不能为空!'); ?>"
                },
                brandSort: {
                    required: "<?php echo $this->translate('排序不能为空!'); ?>",
                    number: "<?php echo $this->translate('排序必须为数字!'); ?>",
                    min: "<?php echo $this->translate('排序最小为1!'); ?>"
                }
            }
        });
    });
</script>
